#include "KeySearchEdit.h"
#include "../../KeySearchWidget.h"
#include <core/StyleMgr.h>

KeySearchEdit::KeySearchEdit(QWidget* parent)
	: QLineEdit(parent)
{
	setClearButtonEnabled(true);
	setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
	setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

	setStyleSheet("border:none;background:transparent;font:bold 12px");
	setFocusPolicy(Qt::FocusPolicy::ClickFocus);
}

void KeySearchEdit::focusInEvent(QFocusEvent* event)
{
	KeySearchWidget* ksw = dynamic_cast<KeySearchWidget*>(parent());
	if (ksw)
		ksw->foucsChanged(true);

	QString style = QString("border:none;background:transparent;color:#%1;font:bold 12px")
		.arg((StyleMgr::instance().color("Highlight").rgb(), 0, 16));

	setStyleSheet(style);
	QLineEdit::focusInEvent(event);
}

void KeySearchEdit::focusOutEvent(QFocusEvent* event)
{
	KeySearchWidget* ksw = dynamic_cast<KeySearchWidget*>(parent());
	if (ksw)
		ksw->foucsChanged(false);

	setStyleSheet("border:none;background:transparent;font:bold 12px");
	QLineEdit::focusOutEvent(event);
}

void KeySearchEdit::mousePressEvent(QMouseEvent* event)
{
	QLineEdit::mousePressEvent(event);
}
